<?php

/**
 * This is the model class for table "{{mem_privilege}}".
 *
 * The followings are the available columns in table '{{mem_privilege}}':
 * @property integer $zmv_id
 * @property integer $zmv_men_id
 * @property integer $zmv_type
 * @property integer $zna_id
 * @property string $parent
 * @property string $child
 * @property integer $inputtime
 * @property integer $updatetime
 */
class MemPrivilege extends CActiveRecord
{
	/**
	 * Returns the static model of the specified AR class.
	 * @param string $className active record class name.
	 * @return MemPrivilege the static model class
	 */
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}

	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return '{{mem_privilege}}';
	}

	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		// NOTE: you should only define rules for those attributes that
		// will receive user inputs.
		return array(
			array('zmv_men_id, zmv_type, zna_id, inputtime, updatetime', 'numerical', 'integerOnly'=>true),
			array('parent, child', 'length', 'max'=>64),
			// The following rule is used by search().
			// Please remove those attributes that should not be searched.
			array('zmv_id, zmv_men_id, zmv_type, zna_id, parent, child, inputtime, updatetime', 'safe', 'on'=>'search'),
		);
	}

	/**
	 * @return array relational rules.
	 */
	public function relations()
	{
		// NOTE: you may need to adjust the relation name and the related
		// class name for the relations automatically generated below.
		return array(
				//'task'=>array(self::HAS_ONE, 'MemGroup', 'parent'),
				'action'=>array(self::HAS_ONE, 'MemGroup', array('name'=>'child'),'select'=>'zmg_title,name'),
		);
	}

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'zmv_id' => 'Zmv',
			'zmv_men_id' => 'Zmv Men',
			'zmv_type' => 'Zmv Type',
			'zna_id' => 'Zna',
			'parent' => 'Parent',
			'child' => 'Child',
			'inputtime' => 'Inputtime',
			'updatetime' => 'Updatetime',
		);
	}

	/**
	 * Retrieves a list of models based on the current search/filter conditions.
	 * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
	 */
	public function search()
	{
		// Warning: Please modify the following code to remove attributes that
		// should not be searched.

		$criteria=new CDbCriteria;

		$criteria->compare('zmv_id',$this->zmv_id);
		$criteria->compare('zmv_men_id',$this->zmv_men_id);
		$criteria->compare('zmv_type',$this->zmv_type);
		$criteria->compare('zna_id',$this->zna_id);
		$criteria->compare('parent',$this->parent,true);
		$criteria->compare('child',$this->child,true);
		$criteria->compare('inputtime',$this->inputtime);
		$criteria->compare('updatetime',$this->updatetime);

		$criteria->order = " inputtime DESC ";//默认为时间倒序
		return new CActiveDataProvider($this, array(
			'criteria'=>$criteria,
		));
	}

	public function DelCatcache(){
		Yii::app()->filecache->delete('front_role_action');
	}
	
	function afterSave(){
		//清空缓存
		$this->DelCatcache();
		return true;
	}
	
	function afterDelete(){
		//清空缓存
		$this->DelCatcache();
		return true;
	}
}